package com.lovo.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.stock.bean.CustomerBean;
import com.lovo.stock.bean.PageInfo;
import com.lovo.stock.bean.SupplierBean;
import com.lovo.stock.mapper.CustomerMapper;
import com.lovo.stock.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerImpl extends ServiceImpl<CustomerMapper, CustomerBean> implements ICustomerService {
    @Autowired
    CustomerMapper customerMapper;

    @Override
    public IPage<CustomerBean> queryCustomerByPage(PageInfo<CustomerBean> pageInfo) {
        QueryWrapper q=new QueryWrapper<>();
        //动态判断,首先判断供应商是否为空
        if (pageInfo.getData()!=null){
            //客户名不为空
            if (pageInfo.getData().getCustomerName()!=null&&!"".equals(pageInfo.getData().getCustomerName())){
                q.like("customer_name",pageInfo.getData().getCustomerName());
            }
            //经营范围不为空
            if (pageInfo.getData().getCustomerNatureOfBusiness()!=null&&!"".equals(pageInfo.getData().getCustomerNatureOfBusiness())){
                q.like("customer_natureOfBusiness",pageInfo.getData().getCustomerNatureOfBusiness());
            }
        }
        IPage<CustomerBean> page=customerMapper.selectPage(new Page<>(pageInfo.getCurPage(), pageInfo.getPageSize()),q);
        return page;
    }

    @Override
    public List<CustomerBean> queryAllCustomer() {
        return customerMapper.selectList(null);
    }

    @Override
    public CustomerBean queryCustomerInfoById(int id) {
        return customerMapper.selectById(id);
    }

    @Override
    public void updateCustomer(CustomerBean customerBean) {
        customerMapper.updateById(customerBean);
    }

    @Override
    public void addCustomer(CustomerBean customerBean) {
        customerMapper.insert(customerBean);
    }
}
